package com.bestcem.xm.award.service.dto.draw;

import com.bestcem.xm.award.entity.pojo.AwardRecordDO;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.Objects;

/**
 * 奖项信息DTO
 *
 * @author hang.li <hang.li@idiaoyan.com>
 * @version v1.0
 * @date 2021/7/13 18:49
 */
@Data
@Accessors(chain = true)
public class RecordDetailDTO {

    /**
     * 抽奖记录id
     */
    private String recordId;

    /**
     * 兑奖码
     */
    private String code;

    /**
     * 奖项名称
     */
    private String name;

    /**
     * 奖项等级
     */
    private Integer level;

    /**
     * 奖项等级描述
     */
    private String levelStr;

    /**
     * 中奖名单奖项信息数据转换
     *
     * @param record 抽奖记录数据
     * @return RecordDetailDTO
     */
    public static RecordDetailDTO awardRecordToRecordDetailDTO(AwardRecordDO record) {
        RecordDetailDTO detailDTO = new RecordDetailDTO();
        detailDTO.setRecordId(record.getId());
        if (Objects.nonNull(record.getWin())) {
            detailDTO.setCode(record.getWin().getCode())
                    .setName(record.getWin().getName())
                    .setLevel(record.getWin().getLevel())
                    .setLevelStr(record.getWin().getLevelStr());
        }
        return detailDTO;
    }
}
